package impl

import (
	"context"
	"deployment-service/jenkins"
	"github.com/bndr/gojenkins"
)

type jenkinsAdapter struct {
	ctx     context.Context
	jenkins *gojenkins.Jenkins
}

func (m jenkinsAdapter) CreateJob(name, config string) (jenkins.IJenkinsJob, error) {
	job, err := m.jenkins.CreateJob(m.ctx, config, name)
	if err != nil {
		return nil, err
	}

	return jobAdapter{
		ctx:     m.ctx,
		jenkins: m.jenkins,
		job:     job,
	}, nil
}

func (m jenkinsAdapter) GetJob(name string) (jenkins.IJenkinsJob, error) {
	job, err := m.jenkins.GetJob(m.ctx, name)
	if err != nil {
		return nil, err
	}

	return jobAdapter{
		ctx:     m.ctx,
		jenkins: m.jenkins,
		job:     job,
	}, nil
}
